<?php

namespace app\teacher\controller\student;

use app\common\controller\Frontend;
use app\common\model\banxi\student\StudentSaySentence as StudentSaySentenceModel;

class StudentSaySentence extends Frontend
{
    protected array $noNeedLogin = [];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
    }


    //列表
    public function listPage()
    {
        $param = $this->request->param(['index', 'limit', 'orderBy', "query"]);
        $StudentSaySentenceModel = new StudentSaySentenceModel();
        if (isset($param['query']['LIKE_sentence'])) {
            if (!empty($param['query']['LIKE_sentence'])){
                $param['query']['LIKE_sentenceEn|sentenceZh'] = $param['query']['LIKE_sentence'];
            }
            unset($param['query']['LIKE_sentence']);
        }
        //查询条件解析
        $where = get_query($param);
        //获取分页数据
        $pageParams = get_page_params($param);
        $list = $StudentSaySentenceModel
            ->where($where)
            ->order(['id' => 'desc'])
            ->paginate([
                'page' => $pageParams['page'],
                'list_rows' => $pageParams['limit']
            ]);
        $this->ok('ok', result_row($list));
    }

    public function del()
    {
        $id = $this->request->param('id');
        $StudentSaySentenceModel = new StudentSaySentenceModel();
        $info = $StudentSaySentenceModel->where('id', $id)->find();
        if (!$info) {
            $this->error('记录不存在');
        }
        $info->delete();
        $this->ok('ok');
    }


}